package com.ktjy.ktmall.dao.impl;

import com.ktjy.ktmall.dao.BaseDao;
import com.ktjy.ktmall.dao.SkuItemDao;
import com.ktjy.ktmall.entity.SkuItem;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @auth wzy
 * @date 2024/10/31 11:00
 */
public class SkuItemDaoImpl extends BaseDao implements SkuItemDao {
    @Override
    public List<SkuItem> findByGoodsId(int goodsId) {
        List<SkuItem> list = new ArrayList<>();
        String sql = "select * from t_sku_info where goods_id=?";
        rs = super.executeQuery(sql, goodsId);
        try {
            while (rs.next()) {
                SkuItem sku = new SkuItem(rs.getInt("id"), rs.getInt("goods_id")
                        , rs.getString("stock_sku"), rs.getBigDecimal("price"), rs.getBigDecimal("old_price"), rs.getLong("inventory"), rs.getString("picture"));
                list.add(sku);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs, pstmt, conn);
        }
        return list;
    }
}
